from selenium import webdriver  # 驱动浏览器
from selenium.webdriver.common.by import By  # 定位
import time


# 打开浏览器
c = webdriver.Chrome()   # 打开谷歌浏览器
c.maximize_window()    # 最大化窗口
# 打开网址
c.get('https://www.qq.com/')
time.sleep(1)

# 定位到第一篇文章
first = c.find_element(By.CSS_SELECTOR, '[class="news-top"] a')
# 拿到标题
title = first.text
# 点击文章，进入详情
first.click()
# 获取所有窗口列表
all_windows = c.window_handles
# 切换窗口
c.switch_to.window(all_windows[1])
time.sleep(2)
# 获取正文元素
# try:
#     content_ele = c.find_element(By.CSS_SELECTOR, '[class="article article-detail1"]')
# except:
#     content_ele = c.find_element(By.CSS_SELECTOR, '[class="article article-detail"]')

content_ele = c.find_element(By.CSS_SELECTOR, '[class="article article-detail"]')
content = content_ele.text



